package com.itzz.spring_zhoneHeng.controller;

import com.itzz.spring_zhoneHeng.base.RestResponse;
import com.itzz.spring_zhoneHeng.pojo.Messages;
import com.itzz.spring_zhoneHeng.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    MessagesService messagesService;

    @RequestMapping("/addMessages")
    @PreAuthorize("hasRole('ROLE_super')")
    //根据前端传输的messages  消息  添加到 messages表中
    //根据传输的用户数组  ids   和messages表中的id 添加进u_ms表中
    public RestResponse addMessages(Messages messages, Integer[] ids){
        RestResponse response = messagesService.addMessages(messages, ids);
        return response;
    }

    //根据传输的messageId 查询u_ms表   删除对应的关系列
    @RequestMapping("/delByMessId")
    public RestResponse delByMessId(Integer[] messids){
        RestResponse response = messagesService.delByMessId(messids);
        return response;
    }

    //用户(所有管理员和用户)
    @RequestMapping("/addMessageByUser")
    //根据前端传输的messages  消息  添加到 messages表中
    //根据传输的用户数组  ids   和messages表中的id 添加进u_ms表中
    public RestResponse addMessagessByUser(Messages messages, Integer[] ids){
        RestResponse response = messagesService.addMessages(messages, ids);
        return response;
    }





}
